package com.lzq.chatroom_project.service.impl;

import com.lzq.chatroom_project.dao.UserMapper;
import com.lzq.chatroom_project.model.User;
import com.lzq.chatroom_project.service.IUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements IUserService {

    private static final Logger log = LoggerFactory.getLogger(UserServiceImpl.class);
    @Autowired
    private UserMapper userMapper;

    @Override
    public User getUserByName(String username) {
        log.info("开始执行getUserByName方法,接收参数:username:{}",username);
        User user = userMapper.selectUserByName(username);
        if (user == null) {
            log.info("未查询到该用户");
            return null;
        }
        return user;
    }

    @Override
    public User getUserById(Integer userId) {
        log.info("开始执行getUserById方法,接收参数:username:{}",userId);
        User user = userMapper.selectUserById(userId);
        if (user == null) {
            log.info("未查询到该用户");
            return null;
        }
        return user;
    }

    @Override
    public Integer addUser(User newUser) {
        log.info("开始执行insertUser方法,接收参数:newUser:{}",newUser);
        Integer ret = userMapper.insertUser(newUser);
        return ret;
    }

}
